﻿using System; 
using System.Text;
using System.Collections.Generic; 
using System.Data;
using Bangle.Common;
using Bangle.Model;
namespace Bangle.BLL {
	 	//T_SaleDetail
		public partial class T_SaleDetailBLL
	{
   		     
		private readonly Bangle.DAL.T_SaleDetailDAL dal=new Bangle.DAL.T_SaleDetailDAL();
		public T_SaleDetailBLL()
		{}
		
		#region  Method
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(Guid SaleDetailId)
		{
			return dal.Exists(SaleDetailId);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public void  Add(Bangle.Model.T_SaleDetail model)
		{
						dal.Add(model);
						
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Bangle.Model.T_SaleDetail model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(Guid SaleDetailId)
		{
			
			return dal.Delete(SaleDetailId);
		}
		
		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Bangle.Model.T_SaleDetail GetModel(Guid SaleDetailId)
		{
			
			return dal.GetModel(SaleDetailId);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public Bangle.Model.T_SaleDetail GetModelByCache(Guid SaleDetailId)
		{
			
			string CacheKey = "T_SaleDetailModel-" + SaleDetailId;
			object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(SaleDetailId);
					if (objModel != null)
					{
						int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
						Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (Bangle.Model.T_SaleDetail)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Bangle.Model.T_SaleDetail> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}

        /// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Bangle.Model.T_SaleDetail> DataTableToList(DataTable dt)
		{
			List<Bangle.Model.T_SaleDetail> modelList = new List<Bangle.Model.T_SaleDetail>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				Bangle.Model.T_SaleDetail model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new Bangle.Model.T_SaleDetail();					
																									if(dt.Rows[n]["SaleDetailId"].ToString()!="")
				{
					model.SaleDetailId= Guid.Parse(dt.Rows[n]["SaleDetailId"].ToString());
				}
																																if(dt.Rows[n]["SaleId"].ToString()!="")
				{
					model.SaleId= Guid.Parse(dt.Rows[n]["SaleId"].ToString());
				}
																								model.PurchaseTime= dt.Rows[n]["PurchaseTime"].ToString();
																																model.PurchaseCode= dt.Rows[n]["PurchaseCode"].ToString();
																																model.PurchaseReceipt= dt.Rows[n]["PurchaseReceipt"].ToString();
																												if(dt.Rows[n]["PurchasePrice"].ToString()!="")
				{
					model.PurchasePrice=decimal.Parse(dt.Rows[n]["PurchasePrice"].ToString());
				}
																																if(dt.Rows[n]["PurchaseAmount"].ToString()!="")
				{
					model.PurchaseAmount=decimal.Parse(dt.Rows[n]["PurchaseAmount"].ToString());
				}
																																if(dt.Rows[n]["Quantity"].ToString()!="")
				{
					model.Quantity=decimal.Parse(dt.Rows[n]["Quantity"].ToString());
				}
																																												if(dt.Rows[n]["SupplierId"].ToString()!="")
				{
					model.SupplierId= Guid.Parse(dt.Rows[n]["SupplierId"].ToString());
				}
																								model.SupplierName= dt.Rows[n]["SupplierName"].ToString();
																												if(dt.Rows[n]["SalePriceUSD"].ToString()!="")
				{
					model.SalePriceUSD=decimal.Parse(dt.Rows[n]["SalePriceUSD"].ToString());
				}
																																if(dt.Rows[n]["SalePriceRMB"].ToString()!="")
				{
					model.SalePriceRMB=decimal.Parse(dt.Rows[n]["SalePriceRMB"].ToString());
				}
																																if(dt.Rows[n]["SaleAmountUSD"].ToString()!="")
				{
					model.SaleAmountUSD=decimal.Parse(dt.Rows[n]["SaleAmountUSD"].ToString());
				}
																																if(dt.Rows[n]["SaleAmountRMB"].ToString()!="")
				{
					model.SaleAmountRMB=decimal.Parse(dt.Rows[n]["SaleAmountRMB"].ToString());
				}
																																if(dt.Rows[n]["CreateUserId"].ToString()!="")
				{
					model.CreateUserId=int.Parse(dt.Rows[n]["CreateUserId"].ToString());
				}
																																				model.CreateTime= dt.Rows[n]["CreateTime"].ToString();
																												if(dt.Rows[n]["UpdateUserId"].ToString()!="")
				{
					model.UpdateUserId=int.Parse(dt.Rows[n]["UpdateUserId"].ToString());
				}
																																				model.UpdateTime= dt.Rows[n]["UpdateTime"].ToString();
																												if(dt.Rows[n]["Valid"].ToString()!="")
				{
					model.Valid=int.Parse(dt.Rows[n]["Valid"].ToString());
				}
																										
				
					modelList.Add(model);
				}
			}
			return modelList;
		}
		
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}
#endregion
   
	}
}